package com.s.core.daily_import.remote.vo;

import com.s.core.root.Ad;
import com.s.core.root.CodeFeature;
import com.s.core.root.D;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class RemoteVo {
    public String code;
    public String name;
    public int close;
    public int high;
    public int preClose;
    public int vol;


    public boolean nameEquals(String oriName) {
        if (CodeFeature.isCqName(name)) {
            return true;
        }
        return name.replaceAll("\\s+", "").replaceAll("Ａ", "A").
                equals(oriName.replaceAll("\\s+", "").replaceAll("Ａ", "A"));
    }

    public static List<String> toCodes(List<RemoteVo> voList) {
        return voList.stream().map(RemoteVo::getCode).collect(Collectors.toList());
    }

    public static RemoteVo getByCode(List<RemoteVo> voList, String code) {
        return voList.stream().filter(vo -> vo.getCode().equals(code)).findFirst().orElse(null);
    }

    public boolean isCq() {
        List<D> bDailyList = Ad.me().getCodeDailyListMap().get(code);
        if (bDailyList == null) {
            return false;
        }
        D ad = bDailyList.stream().filter(t -> !t.isTp()).findFirst().orElse(null);
        String preClose = ad == null ? null : ad.getClose();
        return preClose != null && BigDecimal.valueOf(this.preClose).compareTo(new BigDecimal(preClose).multiply(BigDecimal.valueOf(100))) != 0;
    }
}
